package com.cqs.example.io.example2;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author lixw
 * @Date 7/17/20 11:07 PM
 */
@Slf4j
public class BIOServer2 {

    /**
     * 端口号
     */
    private static final int PORT = 8020;
    private static ExecutorService exec = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws IOException {
        ServerSocket server = null;
        try {
            server = new ServerSocket(PORT);
            Socket socket = null;
            while (true) {
                socket = server.accept();
                exec.submit(new TimeServerHandler2(socket));
            }
        } catch (Throwable e) {
            log.warn("socket通信异常", e);
        } finally {
            if (server != null) {
                log.warn("server close.");
                server.close();
            }
        }
    }
}
